<template>
  <Modal
          :title="title"
          v-model="subReportShow"
          width="600px"
          :closable="false"
  >
    <div slot="footer">
      <i-button @click="hyperlinksCancel('linkData')">取消</i-button>
      <i-button type="primary" @click="hyperlinksOk('linkData')">确定</i-button>
    </div>
    <i-form ref="linkData" :model="linkData" :label-width="100">
      <form-item label="参数" prop="linkCode">
        <i-select :transfer="true" clearable v-model="linkData.linkCode" @on-change="linkCodeChange">
          <i-option v-for="(item,i) in paramsOptions" :value="item.linkCode" :key="i">{{item.linkName}}</i-option>
        </i-select>
      </form-item>
    </i-form>
  </Modal>
</template>
<script>
export default{
  name: 'main-params-report',
      props: {
      excel: {
        type: String,
        required: true,
        default: ""
      }
    },
    data() {
      return {
        title: "",
        subReportShow: false,
        linkData: {
          id: "",
          reportId: "",//积木设计器id
          parameter: "",//参数JSON串
          linkCode: "",
          linkName: "",
          linkFormat: ""
        },
        paramsOptions: []
      }
    },
    watch: {
      'paramData': function (val) {

      }
    },
    methods: {
      //网络报表点击事件
      hyperlinksOk(name) {
        this.$refs[name].validate((valid) => {
          if (valid) {
            debugger;
            let linkData = this.linkData;
            if (linkData.linkFormat != null && linkData.linkFormat != ''){
                linkData.linkType = "1"
            }else{
                linkData.linkType = "4"
            }
            linkData.reportId = excel_config_id
            this.$http.post({
              url: this.api.linkSaveAndEdit,
              contentType: 'json',
              data: JSON.stringify(linkData),
              success: (result) => {
                this.close(name);
                let item = {id:result,};
                this.$emit('set-mainparams',{data:result});
              }
            });
          }
        })
      },
      hyperlinksCancel(name) {
        this.close(name);
      },
      close(name) {
        this.subReportShow = false
        this.paramsOptions=[]
        this.title=""
        this.linkData={}
      },
      //主报表值改变事件
      linkCodeChange(val) {
          debugger
        let list = this.paramsOptions.filter((item) => {
          return item.linkCode == val;
        });

        if (list != null){
            let item = list[0];
            this.linkData.id = item.id;
            this.linkData.linkName = item.linkName;
            this.linkData.linkCode = item.linkCode;
            this.linkData.linkFormat = item.linkFormat;
            this.linkData.reportId = item.reportId;
        }
      },
      getparamsList(reportId) {
          let that = this;
          this.$http.get({
              url:this.api.getMainParams,
              data:{
                  token:that.token,
                  reportId:reportId
              },
              success:(result)=>{
                  if (result!= null){
                      let list = result;
                      that.paramsOptions = [];

                      list.forEach(item => {
                          let aItem  = {linkCode:item.paramName,linkName:item.paramTxt,linkFormat:item.searchFormat};
                          that.paramsOptions.push(aItem);
                      })
                  }
              },
              error:(err)=>{
                  that.handleSpinHide();
              }
          },that)
      }
    }
}
</script>
<style>
    .ivu-form-item-error-tip {
        position: relative;
    }
</style>